﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master"
    Inherits="InStoreDataMeasures_MeasuresDetail_SelectCustomer" CodeFile="MeasuresGroup_SelectCustomer.aspx.cs" %>

<%@ Register Src="~/UserControl/GridPager.ascx" TagName="GridPager" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>指标明细列表 </title>
    <link rel="stylesheet" href="../css/zTreeStyle/demo.css" type="text/css" />
    <link rel="stylesheet" href="../css/zTreeStyle/zTreeStyle.css" type="text/css" />
    <script type="text/javascript" src="../js/jquery.ztree.core-3.1.js"></script>
    <script type="text/javascript" src="../js/jquery.ztree.excheck-3.1.js"></script>
    <script src="../js/jquery.ztree.exedit-3.1.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
		<!--
        var setting = {
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
		        beforeCheck: zTreeBeforeCheck,
                beforeClick: zTreeBeforeClick
	        }
           
   
     };

     function zTreeBeforeCheck(treeId, treeNode) {
     if(!treeNode.checked)
        return confirm('是否覆盖现有指标组?');
     else
        return true;
    };

    function zTreeBeforeClick(treeId, treeNode, clickFlag) {
        if(treeNode.message=='true')
        {
          if(confirm('是否覆盖现有指标组?'))
         {
              zTree.checkNode(treeNode, true, true);
              return true;
         }
         else
            return false;
        }
        else
        {
            zTree.checkNode(treeNode, true, true);
            return true;
        }
    };



        var code;
        var zTree= $.fn.zTree.getZTreeObj("customerTree");
        function setCheck() {
            zTree= $.fn.zTree.getZTreeObj("customerTree");
            zTree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };

        }

        $(document).ready(function () {
            var zNodes = <%=jsoncustomers %>;
            $.fn.zTree.init($("#customerTree"), setting, zNodes);
            setCheck();
            addCustomers();
                });
       
       
        function addCustomers()
        {
            listCustomers=$get('<%=listCustomers.ClientID %>');
            hidcustomers=$get('<%=hidcustomers.ClientID %>');
            hidcustomers.value="";
            var nodes = zTree.getCheckedNodes(true);
            var length = nodes.length;
            var op;
            var j=0;
          //alert(nodes[i].pId!=null);
           
            for (var i=0, l=nodes.length; i < l; i++) {
                
                if(nodes[i].pId!=null)
                {   
	                op=new Option(nodes[i].name,nodes[i].id,true,true);
                    op.tId=nodes[i].tId;
                    op.selected=false;
                    listCustomers.options[j] =op;
                    //zTree.removeNode(nodes[i]);
                    hidcustomers.value=hidcustomers.value+",'"+nodes[i].id+"'";
                    j++;
                }
                
            }
   
           
        }

         function removeCustomers()
        {
            listCustomers=$get('<%=listCustomers.ClientID %>');

            var nodes = zTree.getCheckedNodes(true);
            var length = listCustomers.options.length;
            if(listCustomers.selectedIndex==-1)
            {
                alert('没有选择任何客户');
                return;
            }
            for(var i=listCustomers.options.length-1;i >=0;i--) 
            {   
                var item = listCustomers.options[i]; 
                if(item.selected) 
                { 
                    var op=listCustomers.options[i];
                    //listCustomers.options.removeChild(op);
                    op.parentNode.removeChild(op);

                    zTree.checkNode(zTree.getNodeByTId(op.tId), false, true);
                } 
                        
            } 
            hidcustomers.value="";
             for(var i=0;i<listCustomers.options.length;i++) 
            { 
                hidcustomers.value=hidcustomers.value+",'"+listCustomers.options[i].value+"'";
            }
           
        }
     
        function cancelSelecte(tId)//取消节点选择
        {
             var nodes = zTree.getSelectedNodes();
             for (var i=0, l=nodes.length; i < l; i++) {
             if(nodes[i].id==id)
             {
	            zTree.checkNode(nodes[i], true, true);
                return;
              }
            }


        }
       

		//-->
    </script>
    <table id="wsd_inputtable" width="100%">
        <tr>
            <td class="tabletitle" colspan="7">
                指标明细分配
            </td>
        </tr>
        <tr>
            <td class="tablefield">
                关键字：
            </td>
            <td>
                <asp:TextBox ID="txt_key" runat="server"></asp:TextBox>
            </td>
            <td class="tablefield">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
            <td class="tablefield">
                有效：
            </td>
            <td>
                <asp:DropDownList ID="ddl_active" runat="server">
                    <asp:ListItem Value="">--全部--</asp:ListItem>
                    <asp:ListItem Selected="True" Value="1">--有效--</asp:ListItem>
                    <asp:ListItem Value="0">--无效--</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td>
                <asp:Button ID="btnSearch" runat="server" class="wsd_button2" CausesValidation="false"
                    Text="查 询" OnClick="btnSearch_Click" />
            </td>
        </tr>
    </table>
    <div>
        <table  id="wsd_listtable" style="height:400px">
            <tr>
                <td style="vertical-align: top;height:400px">
                        <ul id="customerTree" class="ztree">
                        </ul>
                </td>
                <td style="width: 20px;vertical-align:middle;">
                    <input class="wsd_button2" onclick="addCustomers();" type="button" value="> >" />
                    <input class="wsd_button2" onclick="removeCustomers();" type="button" value="< <" />
                </td>
                <td style="width:300px;vertical-align: top;">
                    <asp:ListBox ID="listCustomers" runat="server" Width="100%" Height="100%" SelectionMode="Multiple">
                    
                    </asp:ListBox>
                    <asp:HiddenField ID="hidcustomers" runat="server" />
                         </td>
            </tr>
        </table>
        <asp:HiddenField ID="HiddenField1" runat="server" />
        <br />
        <table id="wsd_inputtable">
            <tr>
                <td width="100%" class="tabletitle">
                    操作选项
                </td>
            </tr>
            <tr>
                <td class="buttonarea">
                    <asp:Button ID="btnSave" runat="server" CausesValidation="false" class="wsd_button2"
                        Text="保 存" OnClick="btnSave_Click" Style="height: 21px" />
                    <input class="wsd_button2" onclick="window.history.go(-1);" type="button" value="返  回" />
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
